finding the gradient vector